<!--
 * @Author: wjk
 * @Date: 2019-12-31 15:40:51
 * @LastEditors: wjk
 * @LastEditTime: 2020-08-27 14:18:54
 * @description: file content
 -->
<template>
  <base-page-view class-name="box-list-container">
    <view class="list-container">
      <view v-for="(item, index) in list" :key="index" class="list-item" @click="itemClick(item)">
        <b-image :src="item.pic" mode="widthFix" />
        <view class="item-detail">
          <view class="name">{{ item.title }}</view>
          <view class="desc">{{ item.subtitle }}</view>
          <view class="price-line">
            <view class="sub-item"> <view class="price">{{ item.region_price | formatMoney }}</view></view>
            <!-- <view class="view-btn">立即购买</view> -->
            <image class="in-icon" src="/static/images/icon/icon_more_list.png" mode="aspectFit" />
          </view>
        </view>
      </view>
    </view>
  </base-page-view>
</template>

<script>
import { formatUrlParam } from '@/utils/tools'
import './index.scss'
export default {
  components: {
  },
  data() {
    return {
      series_id: '',
      from_type: '',
      list: [],
      box_series: {}
    }
  },
  created() {
  },
  onLoad(option) {
    this.list = []
    this.from_type = option.from_type
    const title = decodeURIComponent(option.title)
    this.series_id = decodeURIComponent(option.series_id)
    this.$setNavTitle(title)
    this.fetchData()
  },
  onPullDownRefresh() {
    this.fetchData()
  },
  methods: {
    async fetchData() {
      const res = await this.$api.earnApi.earningBoxDetail({
        series_id: this.series_id,
        page_no: 1,
        page_size: 999
      })
      if (res.success && res.data) {
        this.list = res.data.box_goods || []
        this.box_series = res.data.box_series || {}
      }
      setTimeout(() => {
        uni.stopPullDownRefresh()
      }, 500)
    },
    itemClick(item) {
      const query = {
        from_type: this.from_type,
        series_id: this.series_id,
        box_id: item.box_id,
        type: 'boxGoods'
      }
      const url = formatUrlParam('/pagesDetail/commodity/index', query)
      this.$navigateTo(url)
    }
  }
}
</script>
